Fuente: Reportes de la Verificación Nacional Muestral (2003-2017). DERFE-Dirección de Estadística.
---
title: "Verificación Nacional Muestral - Cobertura. Periodo: 2003-2017"
author: "DERFE-Dirección de Estadística"
output:
flexdashboard::flex_dashboard:
orientation: rows
source_code: embed
logo: ine_logo2.png
---
Fuente: Reportes de la Verificación Nacional Muestral (2003-2017). DERFE-Dirección de Estadística.
```{r setup, include=FALSE}
library(ggplot2)
library(plotly)
library(tidyverse)
library(flexdashboard)
#----------------------------------------------------------------------------------#
################################# Paquetes y setup #################################
#----------------------------------------------------------------------------------#
library(pacman)
p_load(tidyverse,
lubridate,
plotly,
ggthemes,
RColorBrewer)
#Prevenir notación científica
options(scipen=999)
#Getting the path of your current open file
#current_path = rstudioapi::getActiveDocumentContext()$path
#setwd(dirname(current_path))
#print(getwd())
#----------------------------------------------------------------------------------#
############################# Datos originales #####################################
#----------------------------------------------------------------------------------#
Datos_VNM_C2 <- read_csv("Datos_VNM_Cobertura_Proc.csv",
locale = locale(encoding = 'latin1'),
col_types = cols(Fecha = col_date(format = "%Y")))
Datos_VNM_C2$Edo <- as.factor(Datos_VNM_C2$Edo)
Datos_VNM_C2$Nombre_Indicador <- as.factor(Datos_VNM_C2$Nombre_Indicador)
#----------------------------------------------------------------------------------#
############################# transformacion de datos ##############################
#----------------------------------------------------------------------------------#
Datos_VNM_C3 <- Datos_VNM_C2 %>% filter(Edo != 'Nacional')
Datos_VNM_C3$Edo <- as.character(Datos_VNM_C3$Edo)
Datos_VNM_C3$Edo <- as.factor(Datos_VNM_C3$Edo)
#----------------------------------------------------------------------------------#
############################### opciones estéticas #################################
#----------------------------------------------------------------------------------#
f <- list(
size = 14,
color = "#7f7f7f"
)
xx <- list(
title = "Fecha",
titlefont = f
)
xx2 <- list(
title = "Entidad",
titlefont = f
)
yy <- list(
title = "Porcentaje (%)",
titlefont = f
)
l <- list(
font = list(
size = 8,
color = "#000"),
orientation = 'v',
x = -400,
y = 0.5)
l1 <- list(
font = list(
size = 8,
color = "#000"),
orientation = 'h')
# funcion para generar la lista de opciones del menu
#(ver: https://stackoverflow.com/questions/55075168/loop-plotly-menu)
get_menu_list <- function(names){
n_names = length(names)
buttons = vector("list",n_names)
for(i in seq_along(buttons)){
buttons[i] = list(list(method = "restyle",
args = list("transforms[0].value", names[i]),
label = names[i]))
}
return_list = list(
list(
type = 'dropdown',
active = 0,
buttons = buttons
)
)
return(return_list)
}
```
Gráfica 1
=======================================================================
Row
-----------------------------------------------------------------------
### Indicadores de cobertura, a nivel nacional y estatal
```{r}
fig <- Datos_VNM_C2 %>%
plot_ly(
x = ~Fecha,
y = ~Indicador,
customdata = ~Edo,
color = ~Nombre_Indicador,
text = ~paste(Edo,
'
Año:', year(Fecha),
'
Indicador:', Nombre_Indicador,
'
Porcentaje:', Indicador,'%'),
hoverinfo = 'text',
transforms = list(
list(
type = 'filter',
target = 'customdata',
operation = '=',
value = unique(Datos_VNM_C2$Edo)[1]
)
)) %>%
add_trace(type = 'scatter',
mode='lines+markers',
visible = 'legendonly'
)%>%
layout(xaxis = xx,
yaxis = yy,
legend = list(
font = list(
size = 10,
color = "#000"),
orientation = 'h',
x = 0.0,
y = -0.2),
updatemenus = list(
list(direction = "right",
xanchor = 'right',
yanchor = "top",
x = 0.1,
y= 1.1,
font = list(
size = 10),
type = 'dropdown',
active = 0,
buttons = apply(as.data.frame(as.factor(unique(Datos_VNM_C2$Edo))), 1,
function(x) list(method = 'restyle',args = list('transforms[0].value',x),label = x)))
)
)
fig
```
Gráfica 2
=======================================================================
Row
-----------------------------------------------------------------------
### Evolución de los indicadores de cobertura, a nivel nacional y estatal
```{r}
fig1 <- Datos_VNM_C2 %>%
plot_ly(x = ~Fecha,
y = ~Indicador,
color = ~factor(Edo, levels=as.character(unique(Datos_VNM_C2$Edo))),
customdata = ~Nombre_Indicador,
hoverinfo = 'text',
text = ~paste(Edo,
'
Año:', year(Fecha),
'
Indicador:', Nombre_Indicador,
'
Porcentaje:', Indicador,'%'),
transforms = list(
list(
type = 'filter',
target = ~'customdata',
operation = '=',
value = as.factor(unique(Datos_VNM_C2$Nombre_Indicador)[1])))
) %>%
add_trace(type = 'scatter',
mode='lines+markers',
visible = 'legendonly'
) %>%
layout(xaxis = xx,
yaxis = yy,
legend = list(
font = list(
size = 10,
color = "#000"),
orientation = 'v',
x = -0.2,
y = 0.9),
updatemenus = list(
list(direction = "right",
xanchor = 'left',
yanchor = "top",
x = 0.0,
y= 1.1,
font = list(
size = 10),
type = 'dropdown',
active = 0,
buttons = apply(as.data.frame(as.factor(unique(Datos_VNM_C2$Nombre_Indicador))), 1,
function(x) list(method = 'restyle',args = list('transforms[0].value',x),label = x)))
)
)
fig1
```
Gráfica 3
=======================================================================
Row
-----------------------------------------------------------------------
### Indicadores de cobertura por año, y por entidad federativa
```{r}
fig2 <- plot_ly(Datos_VNM_C3,
x = ~Edo,
y = ~Indicador,
customdata = ~Fecha,
color = ~Nombre_Indicador,
type = 'bar',
visible = 'legendonly',
hoverinfo = 'text',
text = ~paste(Edo,
'
Indicador:', Nombre_Indicador,
'
Porcentaje:', Indicador,'%'),
transforms = list(
list(
type = 'filter',
target = 'customdata',
operation = '=',
value = year(unique(Datos_VNM_C3$Fecha)[1])
))) %>%
layout(barmode = 'group',
xaxis = xx2,
yaxis = yy,
legend = list(
font = list(
size = 10,
color = "#000"),
orientation = 'h',
x = 0.0,
y = -0.2),
updatemenus = list(
list(direction = "right",
xanchor = 'left',
yanchor = "top",
x = 0.0,
y= 1.2,
font = list(
size = 10),
type = 'dropdown',
active = 0,
buttons = apply(as.data.frame(year(unique(Datos_VNM_C3$Fecha))), 1,
function(x) list(method = 'restyle',args = list('transforms[0].value',x),label = x)))
))
fig2
```